define([
	'../index',
	'../api',
    'text!./index.html',
    'css!./index.css'
], function(ohcards, api, html) {
    return {
		inject: ['appPaddingBottom'],
		props: {
			room:{
				type:Object,
				default:{
					id:0,
					is_adult:0,
				},
			}
		},
	    data: function(){
			return {
				sort: {},
				sortIds: JSON.parse(this.room.cards_id),
				imageShow:true,
			}
	    },
	    created:function(){
			this.appPaddingBottom = '300px';
			this.getSort();
	    },
	    methods:{
		    prev: function(){
				const step = this.room.step - 1
				api.setStep(this.room.id,step)
				.then((res)=>{
					this.room.step = step;
				})
		    },
			show: function(isShow){
				this.imageShow = isShow;
				if(this.appPaddingBottom!=undefined){
					if(isShow){
						this.appPaddingBottom = '300px';
					}else{
						this.appPaddingBottom = '20px';
					}
				}
			},
			save: function(){
				api.saveAnalysis(this.room.id, this.room.analysis);
				Layer.msg('保存成功');
			},
			getSort: function(){
				let ids = Object.values(this.sortIds);
				if(ids.length>0){
					api.getCards({ids:ids})
					.then((res) => {
						res.data.forEach((image,index)=>{
							let sort = this.getImageSortById(image.id);
							this.sort[sort] = image;
						})
					})
				}
			},
			getImageSortById: function(card_id){
				let sort = -1;
				const valIndex = Object.values(this.sortIds).indexOf(card_id);
				if(valIndex >= 0) sort = Object.keys(this.sortIds)[valIndex];
				return sort;
			},
			getSrc: function(index){
				if(this.sort[index]) return this.sort[index].image;
			},
		},
        template: html
    };
});